\section{Function Reference}

\subsection*{abs($x$)}

Returns the absolute value or vector length of $x$.

{\color{blue}
\begin{verbatim}
X = (x,y,z)
abs(X)
\end{verbatim}
}

\noindent
$\left(x^2+y^2+z^2\right)^{1/2}$

\subsection*{adj($m$)}

Returns the adjunct of matrix $m$.
Adjunct is equal to determinant times inverse.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
adj(A) == det(A) inv(A)
\end{verbatim}
}

\noindent
$1$

\subsection*{and($a,b,\ldots$)}

Returns 1 if all arguments are true (nonzero).
Returns 0 otherwise.

{\color{blue}
\begin{verbatim}
and(1=1,2=2)
\end{verbatim}
}

\noindent
$1$

\subsection*{arccos($x$)}

Returns the arc cosine of $x$.

{\color{blue}
\begin{verbatim}
arccos(1/2)
\end{verbatim}
}

\noindent
$\tfrac{1}{3}\pi$

\subsection*{arccosh($x$)}

Returns the arc hyperbolic cosine of $x$.

\subsection*{arcsin($x$)}

Returns the arc sine of $x$.

{\color{blue}
\begin{verbatim}
arcsin(1/2)
\end{verbatim}
}

\noindent
$\tfrac{1}{6}\pi$

\subsection*{arcsinh($x$)}

Returns the arc hyperbolic sine of $x$.

\subsection*{arctan($y,x$)}

Returns the arc tangent of $y$ over $x$.
If $x$ is omitted then $x=1$ is used.

{\color{blue}
\begin{verbatim}
arctan(1,0)
\end{verbatim}
}

\noindent
$\tfrac{1}{2}\pi$

\subsection*{arctanh($x$)}

Returns the arc hyperbolic tangent of $x$.

\subsection*{arg($z$)}

Returns the angle of complex $z$.

{\color{blue}
\begin{verbatim}
arg(2 - 3i)
\end{verbatim}
}

\noindent
$\arctan(-3,2)$

\subsection*{besselj($x,n$)}

Returns a solution to the Bessel differential equation.

{\color{blue}
\begin{verbatim}
besselj(x,1/2)
\end{verbatim}
}

\noindent
$\displaystyle \frac{2^{1/2}\sin(x)}{\pi^{1/2}\,x^{1/2}}$

\subsection*{binding($s$)}

The result of evaluating a symbol can differ from the symbol's binding.
For example, the result may be expanded.
The {\tt binding} function returns the actual binding of a symbol.

{\color{blue}
\begin{verbatim}
p = quote((x + 1)^2)
p
\end{verbatim}
}

\noindent
$p=x^2+2x+1$

{\color{blue}
\begin{verbatim}
binding(p)
\end{verbatim}
}

\noindent
$(x+1)^2$

\subsection*{binomial($n,k$)}

Returns the coefficient of $x^ky^{n-k}$ in $(x+y)^n$.

{\color{blue}
\begin{verbatim}
binomial(52,5)
\end{verbatim}
}

\noindent
$2598960$

\bigskip
\noindent
Note:
\verb$binomial$
and
\verb$choose$
are the same function.

\subsection*{ceiling($x$)}

Returns the smallest integer greater than or equal to $x$.

{\color{blue}
\begin{verbatim}
ceiling(1/2)
\end{verbatim}
}

\noindent
$1$

\subsection*{check($x$)}

If $x$ is true (nonzero) then continue, else stop.
Expression $x$ can include the relational operators
\verb$=$,
\verb$==$,
\verb$<$,
\verb$<=$,
\verb$>$,
\verb$>=$.
Use the
\verb$not$
function to test for inequality.

{\color{blue}
\begin{verbatim}
A = 1
B = 1
check(A=B) -- stop here if A not equal to B
\end{verbatim}
}

\subsection*{choose($n,k$)}

Returns the number of combinations of $n$ items taken $k$ at a time.
The following example computes the number of poker hands.

{\color{blue}
\begin{verbatim}
choose(52,5)
\end{verbatim}
}

\noindent
$2598960$

\subsection*{circexp($x$)}

Returns expression $x$ with circular and hyperbolic functions
converted to exponentials.

{\color{blue}
\begin{verbatim}
circexp(cos(x) + i sin(x))
\end{verbatim}
}

\noindent
$\exp(ix)$

\subsection*{clear}

Clears all symbol definitions.

\subsection*{clock($z$)}

Returns complex $z$ in polar form with base of negative 1 instead of $e$.

{\color{blue}
\begin{verbatim}
clock(2 - 3i)
\end{verbatim}
}

\noindent
$13^{1/2}\,(-1)^{\arctan(-3,2)/\pi}$

\subsection*{coeff($p,x,n$)}

Returns the coefficient of $x^n$ in polynomial $p$.

{\color{blue}
\begin{verbatim}
p = x^3 + 6x^2 + 12x + 8
coeff(p,x,2)
\end{verbatim}
}

\noindent
$6$

\subsection*{cofactor($m,i,j$)}

Returns a cofactor of matrix $m$.
The cofactor matrix is the transpose of the adjunct of $m$.
This function returns the cofactor component at row $i$ and column $j$.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
cofactor(A,1,2) == transpose(adj(A))[1,2]
\end{verbatim}
}

\noindent
$1$

\subsection*{conj($z$)}

Returns the complex conjugate of $z$.

{\color{blue}
\begin{verbatim}
conj(2 - 3i)
\end{verbatim}
}

\noindent
$2 + 3 i$

\subsection*{contract($a,i,j$)}

Returns tensor $a$ summed over indices $i$ and $j$.
If $i$ and $j$ are omitted then 1 and 2 are used.
The expression {\tt contract(m)} computes the trace of matrix $m$.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
contract(A)
\end{verbatim}
}

\noindent
$a + d$

\subsection*{cos($x$)}

Returns the cosine of $x$.

{\color{blue}
\begin{verbatim}
cos(pi/4)
\end{verbatim}
}

\noindent
$\displaystyle \frac{1}{2^{1/2}}$

\subsection*{cosh($x$)}

Returns the hyperbolic cosine of $x$.

{\color{blue}
\begin{verbatim}
circexp(cosh(x))
\end{verbatim}
}

\noindent
$\tfrac{1}{2}\exp(-x)+\tfrac{1}{2}\exp(x)$


\subsection*{cross($u,v$)}

Returns the cross product of vectors $u$ and $v$.
It is OK to redefine {\tt cross}.
This is the default definition.

{\color{blue}
\begin{verbatim}
cross(u,v) = (u[2] v[3] - u[3] v[2],
              u[3] v[1] - u[1] v[3],
              u[1] v[2] - u[2] v[1])
\end{verbatim}
}

\subsection*{curl($u$)}

Returns the curl of vector $u$.
It is OK to redefine {\tt curl}.
This is the default definition.

{\color{blue}
\begin{verbatim}
curl(u) = (d(u[3],y) - d(u[2],z),
           d(u[1],z) - d(u[3],x),
           d(u[2],x) - d(u[1],y))
\end{verbatim}
}

\subsection*{d($f,x$)}

Returns the partial derivative of $f$ with respect to $x$.

{\color{blue}
\begin{verbatim}
d(x^2,x)
\end{verbatim}
}

\noindent
$2x$

\bigskip
\noindent
Argument $f$ can be a tensor of any rank.
Argument $x$ can be a vector.
When $x$ is a vector the result is the gradient of $f$.

{\color{blue}
\begin{verbatim}
F = (f(),g(),h())
X = (x,y,z)
d(F,X)
\end{verbatim}
}

\noindent
$\displaystyle \begin{bmatrix}
\operatorname{d}(f(),x) & \operatorname{d}(f(),y) &  \operatorname{d}(f(),z)\\
\operatorname{d}(g(),x) & \operatorname{d}(g(),y) &  \operatorname{d}(g(),z)\\
\operatorname{d}(h(),x) & \operatorname{d}(h(),y) &  \operatorname{d}(h(),z)
\end{bmatrix}
$

\bigskip
\noindent
It is OK to use {\tt d} as a variable name.
It will not conflict with function {\tt d}.

\bigskip
\noindent
It is OK to redefine {\tt d} as a different function.
The function {\tt derivative}, a synonym for {\tt d},
can still be used to obtain a partial derivative.

\subsection*{defint($f,x,a,b$)}

Returns the definite integral of $f$ with respect to $x$
evaluated from $a$ to $b$.
The argument list can be extended for multiple integrals
as shown in the following example.

{\color{blue}
\begin{verbatim}
f = (1 + cos(theta)^2) sin(theta)
defint(f, theta, 0, pi, phi, 0, 2pi) -- integrate over theta then over phi
\end{verbatim}
}

\noindent
$\tfrac{16}{3}\pi$

\subsection*{deg($p,x$)}

Returns the degree of polynomial $p(x)$.

{\color{blue}
\begin{verbatim}
p = (2x + 1)^3
deg(p,x)
\end{verbatim}
}

\noindent
$3$

\subsection*{denominator($x$)}

Returns the denominator of expression $x$.

{\color{blue}
\begin{verbatim}
denominator(a/b)
\end{verbatim}
}

\noindent
$b$

\subsection*{det($m$)}

Returns the determinant of matrix $m$.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
det(A)
\end{verbatim}
}

\noindent
$a d - b c$

\subsection*{dim($a,n$)}

Returns the dimension of the $n$th index of tensor $a$.
Index numbering starts with 1.

{\color{blue}
\begin{verbatim}
A = ((1,2),(3,4),(5,6))
dim(A,1)
\end{verbatim}
}

\noindent
$3$

\subsection*{div($u$)}

Returns the divergence of vector $u$.
It is OK to redefine {\tt div}.
This is the default definition.

{\color{blue}
\begin{verbatim}
div(u) = d(u[1],x) + d(u[2],y) + d(u[3],z)
\end{verbatim}
}

\subsection*{do($a,b,\ldots$)}

Evaluates each argument from left to right.
Returns the result of the final argument.

{\color{blue}
\begin{verbatim}
do(A=1,B=2,A+B)
\end{verbatim}
}

\noindent
$3$

\subsection*{dot($a,b,\ldots$)}

Returns the dot or matrix product of vectors, matrices, and tensors.

{\color{blue}
\begin{verbatim}
-- solve for X in AX=B
A = ((1,2),(3,4))
B = (5,6)
X = dot(inv(A),B)
X
\end{verbatim}
}

\noindent
$\displaystyle \begin{bmatrix}-4\\ \tfrac{9}{2}\end{bmatrix}$

\subsection*{draw($f,x$)}

Draws a graph of $f(x)$.
Drawing ranges can be set with {\tt xrange} and {\tt yrange}.

{\color{blue}
\begin{verbatim}
xrange = (0,1)
yrange = (0,1)
draw(x^2,x)
\end{verbatim}
}

\subsection*{e}

Symbol {\tt e} is initialized to the natural number $e=\exp(1)$.

{\color{blue}
\begin{verbatim}
e^x
\end{verbatim}
}

\noindent
$\exp(x)$

\bigskip
\noindent
Note: It is OK to clear or redefine {\tt e} and use the symbol for something else.

\subsection*{eigen($m$)}

Computes eigenvalues and eigenvectors numerically.
Matrix $m$ is required to be both numerical and symmetric.
Eigenvectors are returned in Q and eigenvalues are returned in D.
Each row of Q is an eigenvector.
Each diagonal element of D is an eigenvalue.

{\color{blue}
\begin{verbatim}
A = ((1,2),(2,1))
eigen(A)
dot(transpose(Q),D,Q)
\end{verbatim}
}

\noindent
$\displaystyle \begin{bmatrix}
1.0 & 2.0\\
2.0 & 1.0
\end{bmatrix}
$

\subsection*{erf($x$)}

Error function of $x$.

\subsection*{erfc($x$)}

Complementary error function of $x$.

\subsection*{eval($f,x,a$)}

Returns $f$ evaluated at $x$ equals $a$.

{\color{blue}
\begin{verbatim}
eval(x^2 + 3,x,0)
\end{verbatim}
}

\noindent
$3$

\subsection*{exp($x$)}

Returns the exponential of $x$.

{\color{blue}
\begin{verbatim}
exp(i pi)
\end{verbatim}
}

\noindent
$-1$

\subsection*{expand($r,x$)}

Returns the partial fraction expansion of the ratio of polynomials $r$ in $x$.

{\color{blue}
\begin{verbatim}
p = (x + 1)^2
q = (x + 2)^2
expand(p/q,x)
\end{verbatim}
}

\noindent
$\displaystyle -\frac{2}{x+2}+\frac{1}{x^2+4x+4}+1$

\subsection*{expcos($z$)}

Returns the cosine of $z$ in exponential form.

{\color{blue}
\begin{verbatim}
expcos(z)
\end{verbatim}
}

\noindent
$\displaystyle \tfrac{1}{2}\exp(iz)+\tfrac{1}{2}\exp(-iz)$

\subsection*{expcosh($z$)}

Returns the hyperbolic cosine of $z$ in exponential form.

{\color{blue}
\begin{verbatim}
expcosh(z)
\end{verbatim}
}

\noindent
$\displaystyle \tfrac{1}{2}\exp(-z)+\tfrac{1}{2}\exp(z)$

\subsection*{expsin($z$)}

Returns the sine of $z$ in exponential form.

{\color{blue}
\begin{verbatim}
expsin(z)
\end{verbatim}
}

\noindent
$\displaystyle -\tfrac{1}{2}i\exp(iz)+\tfrac{1}{2}i\exp(-iz)$

\subsection*{expsinh($z$)}

Returns the hyperbolic sine of $z$ in exponential form.

{\color{blue}
\begin{verbatim}
expsinh(z)
\end{verbatim}
}

\noindent
$\displaystyle -\tfrac{1}{2}\exp(-z)+\tfrac{1}{2}\exp(z)$

\subsection*{exptan($z$)}

Returns the tangent of $z$ in exponential form.

{\color{blue}
\begin{verbatim}
exptan(z)
\end{verbatim}
}

\noindent
$\displaystyle \frac{i}{\exp(2iz)+1}-\frac{i\exp(2iz)}{\exp(2iz)+1}$

\subsection*{exptanh($z$)}

Returns the hyperbolic tangent of $z$ in exponential form.

{\color{blue}
\begin{verbatim}
exptanh(z)
\end{verbatim}
}

\noindent
$\displaystyle -\frac{1}{\exp(2z)+1}+\frac{\exp(2z)}{\exp(2z)+1}$

\subsection*{factor($n$)}

Factors numerical value $n$ and returns the result.

{\color{blue}
\begin{verbatim}
factor(12/35)
\end{verbatim}
}

\noindent
$\displaystyle \frac{2^2\times 3}{5\times 7}$

\bigskip
\noindent
If $n$ is a floating point value then a rational approximation of $n$ is factored and returned.

{\color{blue}
\begin{verbatim}
factor(float(pi))
\end{verbatim}
}

\noindent
$\displaystyle \frac{5\times 71}{113}$

\subsection*{factor($p,x$)}

Factors polynomial $p$ of $x$ and returns the result.
The argument list can be extended for multivariate polynomials.

{\color{blue}
\begin{verbatim}
p = 2x + x y + y + 2
factor(p,x,y)
\end{verbatim}
}

\noindent
$\displaystyle (x+1)(y+2)$

\bigskip
\noindent
Note:
\verb$factor$
returns an unexpanded expression.
If the result is assigned to a symbol, evaluating the symbol will expand the result.
Use
\verb$binding$
to retrieve the unexpanded expression.

{\color{blue}
\begin{verbatim}
q = factor(p,x,y)
binding(q)
\end{verbatim}
}

\noindent
$\displaystyle (x+1)(y+2)$

\subsection*{factorial($n$)}

Returns the factorial of $n$.
The expression {\tt n!} can also be used.

{\color{blue}
\begin{verbatim}
20!
\end{verbatim}
}

\noindent
$2432902008176640000$

\subsection*{filter($f,a,b,\ldots$)}

Returns $f$ excluding any terms containing $a$, $b$, etc.

{\color{blue}
\begin{verbatim}
p = x^2 + 3x + 2
filter(p,x^2)
\end{verbatim}
}

\noindent
$3x+2$

\subsection*{float($x$)}

Returns expression $x$ with rational numbers and integers converted to
floating point values.
The symbol {\tt pi} and the natural number are also converted.

{\color{blue}
\begin{verbatim}
float(212^17)
\end{verbatim}
}

\noindent
$\displaystyle 3.52947\times 10^{39}$

\subsection*{floor($x$)}

Returns the largest integer less than or equal to $x$.

{\color{blue}
\begin{verbatim}
floor(1/2)
\end{verbatim}
}

\noindent
$0$

\subsection*{for($i,j,k,a,b,\ldots$)}

For $i$ equals $j$ through $k$ evaluate $a$, $b$, etc.

{\color{blue}
\begin{verbatim}
for(k,1,3,A=k,print(A))
\end{verbatim}
}

\noindent
$A=1$\\
$A=2$\\
$A=3$

\bigskip
\noindent
Note: The original value of $i$ is restored after {\tt for} completes.
If symbol {\tt i} is used for index variable $i$
then the imaginary unit is overridden in the scope of {\tt for}.

\subsection*{gcd($a,b,\ldots$)}

Returns the greatest common divisor of expressions.

{\color{blue}
\begin{verbatim}
gcd(x,x y)
\end{verbatim}
}

\noindent
$x$

\subsection*{hermite($x,n$)}

Returns the $n$th Hermite polynomial in $x$.

{\color{blue}
\begin{verbatim}
hermite(x,3)
\end{verbatim}
}

\noindent
$\displaystyle 8x^3-12x$


\subsection*{hilbert($n$)}

Returns an $n$ by $n$ Hilbert matrix.

{\color{blue}
\begin{verbatim}
hilbert(3)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
1 & \tfrac{1}{2} & \tfrac{1}{3}\\ \\
\tfrac{1}{2} & \tfrac{1}{3} & \tfrac{1}{4}\\ \\
\tfrac{1}{3} & \tfrac{1}{4} & \tfrac{1}{5}
\end{bmatrix}
$

\subsection*{i}

Symbol {\tt i} is initialized to the imaginary unit $\sqrt{-1}$.

{\color{blue}
\begin{verbatim}
exp(i pi)
\end{verbatim}
}

\noindent
$-1$

\bigskip
\noindent
Note: It is OK to clear or redefine {\tt i} and use the symbol for something else.

\subsection*{imag($z$)}

Returns the imaginary part of complex $z$.

{\color{blue}
\begin{verbatim}
imag(2 - 3i)
\end{verbatim}
}

\noindent
$-3$

\subsection*{inner($a,b,\ldots$)}

Returns the inner product of tensors.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
B = (x,y)
inner(A,B)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
ax+by\\
cx+dy
\end{bmatrix}
$

\bigskip
\noindent
Note: {\tt inner} and {\tt dot} are the same function.

\subsection*{integral($f,x$)}

Returns the integral of $f$ with respect to $x$.

{\color{blue}
\begin{verbatim}
integral(x^2,x)
\end{verbatim}
}

\noindent
$\displaystyle \tfrac{1}{3}x^3$

\subsection*{inv($m$)}

Returns the inverse of matrix $m$.

{\color{blue}
\begin{verbatim}
A = ((1,2),(3,4))
inv(A)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
-2 & 1\\
\tfrac{3}{2} & -\tfrac{1}{2}
\end{bmatrix}
$

\subsection*{isprime($n$)}

Returns 1 if $n$ is a prime number. Returns zero otherwise.

{\color{blue}
\begin{verbatim}
isprime(2^31 - 1)
\end{verbatim}
}

\noindent
1

\subsection*{j}

Set {\tt j=sqrt(-1)} to use {\tt j} for the imaginary unit instead of {\tt i}.

{\color{blue}
\begin{verbatim}
j = sqrt(-1)
1/sqrt(-1)
\end{verbatim}
}

\noindent
$-j$

\subsection*{laguerre($x,n,a$)}

Returns the $n$th Laguerre polynomial in $x$.
If argument $a$ is omitted then $a=0$ is used.

{\color{blue}
\begin{verbatim}
laguerre(x,3)
\end{verbatim}
}

\noindent
$\displaystyle -\tfrac{1}{6}x^3+\tfrac{3}{2}x^2-3x+1$

\subsection*{last}

The result of the previous calculation is stored in {\tt last}.

{\color{blue}
\begin{verbatim}
212^17
\end{verbatim}
}

\noindent
$3529471145760275132301897342055866171392$

{\color{blue}
\begin{verbatim}
last
\end{verbatim}
}

\noindent
$last=3529471145760275132301897342055866171392$

\bigskip
\noindent
Symbol {\tt last} is an implied argument when a function has no argument list.

{\color{blue}
\begin{verbatim}
float
\end{verbatim}
}

\noindent
$\displaystyle 3.52947\times10^{39}$

\subsection*{lcm($a,b,\ldots$)}

Returns the least common multiple of expressions.

{\color{blue}
\begin{verbatim}
lcm(x,x y)
\end{verbatim}
}

\noindent
$xy$

\subsection*{leading($p,x$)}

Returns the leading coefficient of polynomial $p(x)$.

{\color{blue}
\begin{verbatim}
leading(3x^2 + 1,x)
\end{verbatim}
}

\noindent
$3$

\subsection*{legendre($x,n,m$)}

Returns the $n$th Legendre polynomial in $x$.
If $m$ is omitted then $m=0$ is used.

{\color{blue}
\begin{verbatim}
legendre(x,3)
\end{verbatim}
}

\noindent
$\displaystyle \tfrac{5}{2}x^3-\tfrac{3}{2}x$

\subsection*{lisp($x$)}

Evaluates expression $x$ and returns the result as a
string in prefix notation.
Useful for debugging scripts.

{\color{blue}
\begin{verbatim}
lisp(x^2 + 1)
\end{verbatim}
}

\noindent
\verb$(+ (^ x 2) 1)$

\subsection*{log($x$)}

Returns the natural logarithm of $x$.

{\color{blue}
\begin{verbatim}
log(x^y)
\end{verbatim}
}

\noindent
$y\log(x)$

\subsection*{mag($z$)}

Returns the magnitude of complex $z$.
Function {\tt mag} treats undefined symbols as real while {\tt abs} does not.

{\color{blue}
\begin{verbatim}
mag(x + i y)
\end{verbatim}
}

\noindent
$\displaystyle (x^2+y^2)^{1/2}$

\subsection*{mod($a,b$)}

Returns the remainder of $a$ divided by $b$.

{\color{blue}
\begin{verbatim}
mod(10,7)
\end{verbatim}
}

\noindent
$3$

\subsection*{not($x$)}

Returns 0 if $x$ is true (nonzero).
Returns 1 otherwise.

{\color{blue}
\begin{verbatim}
not(1=1)
\end{verbatim}
}

\noindent
$0$

\subsection*{nroots($p,x$)}

Returns all roots, both real and complex,
of polynomial $p(x)$.
The roots are computed numerically.

\subsection*{number($x$)}

Returns 1 if $x$ is a rational or floating point number.
Returns 0 otherwise.

{\color{blue}
\begin{verbatim}
number(1/2)
\end{verbatim}
}

\noindent
$1$

\subsection*{numerator($x$)}

Returns the numerator of expression $x$.

{\color{blue}
\begin{verbatim}
numerator(a/b)
\end{verbatim}
}

\noindent
$a$

\subsection*{or($a,b,\ldots$)}

Returns 1 if at least one argument is true (nonzero).
Returns 0 otherwise.

{\color{blue}
\begin{verbatim}
or(1=1,2=2)
\end{verbatim}
}

\noindent
$1$

\subsection*{outer($a,b,\ldots$)}

Returns the outer product of tensors.
Also known as the tensor product.

{\color{blue}
\begin{verbatim}
A = (a,b,c)
B = (x,y,z)
outer(A,B)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
a x & a y & a z\\
b x & b y & b z\\
c x & c y & c z
\end{bmatrix}
$

\subsection*{pi}

Symbol for $\pi$.

{\color{blue}
\begin{verbatim}
exp(i pi)
\end{verbatim}
}

\noindent
$-1$

\subsection*{polar($z$)}

Returns complex $z$ in polar form.

{\color{blue}
\begin{verbatim}
polar(x - i y)
\end{verbatim}
}

\noindent
$\displaystyle (x^2+y^2)^{1/2}\exp(i\arctan(-y,x))$

\subsection*{power}

Use \verb$^$ to raise something to a power.
Use parentheses for negative powers.

{\color{blue}
\begin{verbatim}
x^(-2)
\end{verbatim}
}

\noindent
$\displaystyle \frac{1}{x^2}$

\subsection*{prime($n$)}

Returns the $n$th prime number.
The domain of $n$ is 1 to 10000.
{\color{blue}
\begin{verbatim}
prime(100)
\end{verbatim}
}

\noindent
$541$

\subsection*{print($a,b,\ldots$)}

Evaluate expressions and print the results.
Useful for printing from inside a {\tt for} loop.

{\color{blue}
\begin{verbatim}
for(j,1,3,print(j))
\end{verbatim}
}

\noindent
$j=1$\newline
$j=2$\newline
$j=3$

\section*{product($i,j,k,f$)}

For $i$ equals $j$ through $k$ evaluate $f$.
Returns the product of all $f$.

{\color{blue}
\begin{verbatim}
product(j,1,3,x + j)
\end{verbatim}
}

\noindent
$\displaystyle x^3+6x^2+11x+6$

\bigskip
\noindent
Note: The original value of $i$ is restored after {\tt product} completes.
If symbol {\tt i} is used for index variable $i$
then the imaginary unit is overridden in the scope of {\tt product}.

\subsection*{quote($x$)}

Returns expression $x$ without evaluating it first.

{\color{blue}
\begin{verbatim}
quote((x + 1)^2)
\end{verbatim}
}

\noindent
$\displaystyle (x+1)^2$

\subsection*{quotient($p,q,x$)}

Returns the quotient of polynomial $p(x)$ over $q(x)$.

{\color{blue}
\begin{verbatim}
p = x^2 + 1
q = x + 3
quotient(p,q,x)
\end{verbatim}
}

\noindent
$x-3$

\subsection*{rank($a$)}

Returns the number of indices that tensor $a$ has.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
rank(A)
\end{verbatim}
}

\noindent
2

\subsection*{rationalize($x$)}

Returns expression $x$ with everything over a common denominator.

{\color{blue}
\begin{verbatim}
rationalize(1/a + 1/b + 1/2)
\end{verbatim}
}

\noindent
$\displaystyle \frac{2a+ab+2b}{2ab}$

\bigskip
\noindent
Note:
\verb$rationalize$
returns an unexpanded expression.
If the result is assigned to a symbol, evaluating the symbol will expand the result.
Use
\verb$binding$
to retrieve the unexpanded expression.

{\color{blue}
\begin{verbatim}
f = rationalize(1/a + 1/b + 1/2)
binding(f)
\end{verbatim}
}

\noindent
$\displaystyle \frac{2a+ab+2b}{2ab}$

\subsection*{real($z$)}

Returns the real part of complex $z$.

{\color{blue}
\begin{verbatim}
real(2 - 3i)
\end{verbatim}
}

\noindent
2

\subsection*{rect($z$)}

Returns complex $z$ in rectangular form.

{\color{blue}
\begin{verbatim}
rect(exp(i x))
\end{verbatim}
}

\noindent
$\displaystyle \cos(x)+i\sin(x)$

\subsection*{roots($p,x$)}

Returns the $x$ such that $p(x)=0$.
Polynomial $p(x)$ should be factorable over integers.
Returns a vector for multiple roots.

{\color{blue}
\begin{verbatim}
roots(x^2 + 3x + 2,x)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
-2\\
-1
\end{bmatrix}
$

\subsection*{run({\it file})}

Run script {\it file}.
Useful for importing function libraries.

{\color{blue}
\begin{verbatim}
run("Downloads/EVA.txt")
\end{verbatim}
}

\noindent
Note: {\it file} must be in the Downloads folder due to security requirements for apps distributed on the Mac App Store.

\subsection*{simplify($x$)}

Returns expression $x$ in a simpler form.

{\color{blue}
\begin{verbatim}
simplify(sin(x)^2 + cos(x)^2)
\end{verbatim}
}

\noindent
1

\subsection*{sin($x$)}

Returns the sine of $x$.

{\color{blue}
\begin{verbatim}
sin(pi/4)
\end{verbatim}
}

\noindent
$\displaystyle \frac{1}{2^{1/2}}$

\subsection*{sinh($x$)}

Returns the hyperbolic sine of $x$.

{\color{blue}
\begin{verbatim}
circexp(sinh(x))
\end{verbatim}
}

\noindent
$\displaystyle -\tfrac{1}{2}\exp(-x)+\tfrac{1}{2}\exp(x)$

\subsection*{sqrt($x$)}

Returns the square root of $x$.

{\color{blue}
\begin{verbatim}
sqrt(10!)
\end{verbatim}
}

\noindent
$\displaystyle 720\; 7^{1/2}$

\subsection*{status}

Prints memory statistics.

\bigskip
\noindent
{\color{blue}
\verb$status$
}

\bigskip
\noindent
\verb$block_count 1$\\
\verb$free_count 99258$\\
\verb$gc_count 1$\\
\verb$bignum_count 370$\\
\verb$string_count 0$\\
\verb$tensor_count 5$

\subsection*{stop}

In a script, it does what it says.

\subsection*{string($x$)}

Evaluates expression $x$ and returns the result as a string.
Useful for testing scripts.

{\color{blue}
\begin{verbatim}
string((x + 1)^2) == "x^2 + 2 x + 1"
\end{verbatim}
}

\noindent
1

\subsection*{subst($a,b,c$)}

Substitutes $a$ for $b$ in $c$ and returns the result.

{\color{blue}
\begin{verbatim}
subst(x,y,y^2)
\end{verbatim}
}

\noindent
$\displaystyle x^2$

\subsection*{sum($i,j,k,f$)}

For $i$ equals $j$ through $k$ evaluate $f$.
Returns the sum of all $f$.

{\color{blue}
\begin{verbatim}
sum(j,1,5,x^j)
\end{verbatim}
}

\noindent
$\displaystyle x^5+x^4+x^3+x^2+x$

\bigskip
\noindent
Note: The original value of $i$ is restored after {\tt sum} completes.
If symbol {\tt i} is used for index variable $i$
then the imaginary unit is overridden in the scope of {\tt sum}.

\subsection*{tan($x$)}

Returns the tangent of $x$.

{\color{blue}
\begin{verbatim}
simplify(tan(x) - sin(x)/cos(x))
\end{verbatim}
}

\noindent
0

\subsection*{tanh($x$)}

Returns the hyperbolic tangent of $x$.

{\color{blue}
\begin{verbatim}
circexp(tanh(x))
\end{verbatim}
}

\noindent
$\displaystyle -\frac{1}{\exp(2x)+1}+\frac{\exp(2x)}{\exp(2x)+1}$

\subsection*{taylor($f,x,n,a$)}

Returns the Taylor expansion of $f(x)$ near $x=a$.
If argument $a$ is omitted then $a=0$ is used.
Argument $n$ is the degree of the expansion.

{\color{blue}
\begin{verbatim}
taylor(sin(x),x,5)
\end{verbatim}
}

\noindent
$\displaystyle \tfrac{1}{120}x^5-\tfrac{1}{6}x^3+x$

\subsection*{test($a,b,c,d,\ldots$)}

If argument $a$ is true (nonzero) then $b$ is returned, else if $c$ is true then $d$ is returned, etc.
If the number of arguments is odd then the final argument is returned if all else fails.
Expressions can include the relational operators
\verb$=$,
\verb$==$,
\verb$<$,
\verb$<=$,
\verb$>$,
\verb$>=$.
Use the
\verb$not$
function to test for inequality.
(The equality operator
\verb$==$
is available for contexts in which
\verb$=$
is the assignment operator.)

{\color{blue}
\begin{verbatim}
A = 1
B = 1
test(A=B,"yes","no")
\end{verbatim}
}

\noindent
yes

\subsection*{trace}

Set {\tt trace=1} in a script to print the script as it is evaluated.
Useful for debugging.

{\color{blue}
\begin{verbatim}
trace = 1
\end{verbatim}
}

\noindent
Note:
The
\verb$contract$
function is used to obtain the trace of a matrix.

\subsection*{transpose($a,i,j$)}

Returns the transpose of tensor $a$ with respect to indices $i$ and $j$.
If $i$ and $j$ are omitted then 1 and 2 are used.
Hence a matrix can be transposed with a single argument.

{\color{blue}
\begin{verbatim}
A = ((a,b),(c,d))
transpose(A)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
a & c\\
b & d
\end{bmatrix}
$

\subsection*{tty}

Set {\tt tty=1} to print results in text format.

{\color{blue}
\begin{verbatim}
tty = 1
(x + 1/2)^2
\end{verbatim}
}

\noindent
\verb$x^2 + x + 1/4$

\subsection*{unit($n$)}

Returns an $n$ by $n$ identity matrix.

{\color{blue}
\begin{verbatim}
unit(3)
\end{verbatim}
}

\noindent
$\displaystyle
\begin{bmatrix}
1 & 0 & 0\\
0 & 1 & 0\\
0 & 0 & 1
\end{bmatrix}
$

\subsection*{zero($i,j,\ldots$)}

Returns a null tensor with dimensions $i$, $j$, etc.
Useful for creating a tensor and then setting component values.

{\color{blue}
\begin{verbatim}
A = zero(3,3)
for(k,1,3,A[k,k]=k)
A
\end{verbatim}
}

\noindent
$\displaystyle
A=
\begin{bmatrix}
1 & 0 & 0\\
0 & 2 & 0\\
0 & 0 & 3
\end{bmatrix}
$
